//数据访问层，数据访问操作


//Share的接口
//可能需要到的注解@Mapper

//已开启mybatis的驼峰命名自动映射开关，在application.properties中配置
package com.rope.backEnd.mapper;

import com.rope.backEnd.pojo.Share;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface ShareMapper {
    /*
    * 查询所有数据
    * */
    @Select("select s.ID,s.userID,u.`name`,s.title_content,s.text_content,s.image,s.publish,s.create_time,s.update_time  " +
            "from rope_database.share s,rope_database.user u where publish = 1 and u.ID = s.userID")
    List<Share> list();

    @Insert("insert into rope_database.share(userID,title_content,text_content,image,publish,create_time,update_time) " +
            "VALUES (#{publish.userID},#{publish.titleContent},#{publish.textContent},#{publish.image},#{publish.publish},NOW(),NOW());")
    int add(@Param("publish") Share publish);

    //查询个人用户所有上传的数据，目前是到需要前端发送用户的ID到后端，
    //该查询语句未更改
    @Select("select s.ID,s.userID,u.`name`,s.title_content,s.text_content,s.image,s.publish,s.create_time,s.update_time  " +
            "from rope_database.share s,rope_database.user u where  #{publishUserID} = s.userID and #{publishUserID} = u.ID")
    List<Share> publishList(@Param("publishUserID") int publishUserID);

    @Update("UPDATE rope_database.share s SET publish = #{statePublish} WHERE id = #{publishUserID};")
    int state(@Param("statePublish") int statePublish,@Param("publishUserID") int publishUserID);

}
